<%@page import="custom.Activity"%>
<%@page import="custom.Announcement"%>
<%@page import="custom.Request"%>
<%@page import="custom.Quiz"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<script type="text/javascript">
	function toggle(id, link) {
		var e = document.getElementById(id);

		if (e.style.display == '') {
			e.style.display = 'none';
			link.innerHTML = 'Expand';
		} else {
			e.style.display = '';
			link.innerHTML = 'Collapse';
		}
	}
</script>
<body>

	
	<%@ include file="header.jsp" %>

	<center><div style="width: 800px; background-color:rgb(256, 256, 230)">
	
		<div align="center" style="margin-bottom: 8px; border:2px solid rgb(200,200,200); background-color: solid rgb(220,220,200)" >
			<div style="font-style: italic; font-weight: 800;">" Admins' announcements </div>
			
			<div id="anno" align="left" style="display:none">
				<%
					ArrayList<Announcement> annos = Announcement.getLastNAnnouncements(-1);
					for(int i=0; i<annos.size(); i++){
						out.print("<p>"+annos.get(i).getHtml()+"</p>");
					}
					if(annos.size() == 0)
						out.print("<p>No recent announcements</p>");
				%>
			</div>
		
			<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
				<a href="#" onclick="toggle('anno', this)" >Expand</a>
				<%
					if (((User) session.getAttribute("user")).areYouAdmin()) {
				%>
						<input type="button" value="add/edit" ONCLICK="window.location.href='editAnnouncements.jsp'" />
				<%
					}
				%>
			</div>
		</div>
		
		
		<div style="float: left; width: 69%; border-right:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200); margin-right: 0.5%;" align="left">
			<div style="margin: 8px">
				<% 
					ArrayList<Activity> acti = ((User) session.getAttribute("user")).getFriendsActivities(); 
				for(int i=0; i<acti.size(); i++){
					out.print("<p>"+acti.get(i).getHtml()+"</p>");
				}
				if(acti.size() == 0)
					out.print("<p>No friend activities</p>");
				%>
				
				
			</div>
		</div>
		
					 
		<div style="float: left; width: 29%; border-left:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200);" align="left">
			<div style="margin: 8px">
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Requests</div>
					
					<div id="Requests" align="left">
						<%
							ArrayList<Request> rec = Request.getAllRequests(((User) session.getAttribute("user")).getId());
							for(int i=0; i<rec.size(); i++){
								out.print("<p>"+rec.get(i).getHtml()+"</p>");
							}
							if(rec.size() == 0)
								out.print("<p>No friend requests</p>");
						%>
					</div>
				
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('Requests', this)" >Collapse</a>
					</div>
				</div>
				
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Popular Quizzes</div>
					
					<div id="Popular Quizzes" align="left" style="display:none">
						<%
							Quiz[] pop= Quiz.popular5();
							int i1;
							for(i1=0; i1<5; i1++){
								if(pop[i1]==null)
									break;
								out.print("<p>"+pop[i1].getNameHtml()+"</p>");
							}
							if(i1==0)
								out.print("<p>No Popular Quizzes</p>");
						%>
					</div>
				
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('Popular Quizzes', this)" >Expand</a>
					</div>
				</div>
				
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Recently Created Quizzes</div>
					
					<div id="Recently Created Quizzes" align="left" style="display:none">
						
						<%
							Quiz[] rcn= Quiz.recent5();
							int i2;
							for(i2=0; i2<5; i2++){
								if(rcn[i2]==null)
									break;
								out.print("<p>"+rcn[i2].getNameHtml()+"</p>");
							}
							if(i2==0)
								out.print("<p>No Recent Quizzes</p>");
						%>
					</div>
				
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('Recently Created Quizzes', this)" >Expand</a>
					</div>
				</div>
								
				<div style="border-bottom: 1px solid rgb(200,200,200)" align="center">
					<div style="font-style: italic; font-weight: 800;">Quizzes By Me</div>
					
					<div id="Quizes By Me" align="left" style="display:none">
						<%
						Quiz[] my= Quiz.fiveBy(((User)session.getAttribute("user")).getId());
						int i3;
						for(i3=0; i3<5; i3++){
							if(my[i3]==null)
								break;
							out.print("<p>"+my[i3].getNameHtml()+"</p>");
						}
						if(i3==0)
							out.print("<p>You haven't created any quizzes yet</p>");
						%>
					</div>
				
					<div style=" margin-right: 5px; margin-bottom: 2px;" align="right">
						<a href="#" onclick="toggle('Quizes By Me', this)" >Expand</a>
					</div>
				</div>				
			</div>
		</div>
		
	</div></center>
</body></html>